<template>
  <el-card class="fontAuth">
    <h1>前端权限示例</h1>
    <CurrentPermissionMode />
    <div class="role">当前角色: {{ roleList }}</div>
    <div>
      角色切换(请先切换权限模式为前端角色权限模式):
      <el-button @click="changeRole(RoleEnum.SUPER)" :type="isSuper ? 'primary' : 'default'"
        >super</el-button
      >
      <el-button @click="changeRole(RoleEnum.TEST)" :type="isTest ? 'primary' : 'default'"
        >test</el-button
      >
    </div>
    <div class="role">切换角色后，请注意“权限测试页A/B”的变化</div>
  </el-card>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import CurrentPermissionMode from '../CurrentPermissionMode.vue'
// 使用该方法导入useStore可以加入ts提示
import { useStore } from '@/store'
import { RoleEnum } from '@/enums/roleEnum'

export default defineComponent({
  components: {
    CurrentPermissionMode
  },
  setup() {
    const store = useStore()

    const roleList = computed(() => store.state.login.roleList)

    function changeRole(role) {
      store.commit('login/setRoleList', [role])
      location.reload()
    }

    return {
      roleList,
      isSuper: computed(() => store.state.login.roleList.includes(RoleEnum.SUPER)),
      isTest: computed(() => store.state.login.roleList.includes(RoleEnum.TEST)),
      changeRole,
      RoleEnum
    }
  }
})
</script>

<style lang="scss" scoped>
.fontAuth {
  height: 1200px;
  font-size: 16px;

  h1 {
    font-size: 24px;
    padding: 10px 0;
  }

  .role {
    padding: 10px 0;
  }
}
</style>
